{include file='head'/}
<title>节点列表</title>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <table id="admin_table" lay-filter="admin_table"></table>
    </div>
    <script type="text/html" id="add_toolbar">
        <button class="layui-btn layui-btn-success layui-btn-sm {if !check_auth('{:__url('system/node/refresh_node')}')}layui-hide{/if}"
                data-confirm="{:__url('system/node/refresh_node')}"
                data-title="确定要更新节点？" data-reload="1"><i class="fa fa-hourglass"></i> 更新节点
        </button>
        <button class="layui-btn layui-btn-sm layui-btn-normal {if !check_auth('{:__url('system/node/refresh_node')}')}layui-hide{/if}"
                data-confirm="{:__url('system/node/refresh_node',['force'=>1])}" data-title="确定要强制更新节点？"
                data-reload="1"><i class="fa fa-hourglass"></i> 强制更新节点
        </button>
        <button class="layui-btn layui-btn-sm layui-btn-danger {if !check_auth('{:__url('system/node/clear_node')}')}layui-hide{/if}"
                data-confirm="{:__url('system/node/clear_node')}"
                data-title="确定清除失效节点？"
                data-reload="1"><i class="fa fa-trash-o"></i> 清除失效节点
        </button>
    </script>
    <script type="text/html" id="typeTpl">
        {{#  if(d.type =='1'){ }}
        <span class="layui-badge layui-bg-danger"> 控制器 </span>
        {{#  } else { }}
        <span class="layui-badge layui-bg-green"> 节&emsp;点 </span>
        {{#  } }}
    </script>
</div>

{include file='footer'/}
</body>
</html>
<script>

  layui.use(['table', 'jquery'], function () {
    var $ = layui.jquery;
    var table = layui.table;
    table.render({
      elem: '#admin_table'
      , toolbar: '#add_toolbar'
      , defaultToolbar: [{
        layEvent: 'refresh',
        icon: 'layui-icon-refresh',
        title: '刷新'
      }, 'filter', 'exports']
      , method: 'get'
      , url: "{:__url('system/node/index')}"
      , parseData: function (res) {
        return {
          "code": res.code_lay,
          "msg": res.msg,
          "count": res.count,
          "data": res.data
        };
      }
      , cellMinWidth: 100
      , cols: [[
        {field: 'id', title: 'ID', width: 60, align: 'center'}
        , {field: 'type', title: '类型', width: 100, align: 'center', templet: '#typeTpl'}
        , {field: 'node', title: '系统节点'}
        , {field: 'title', title: '节点名称'}
        , {field: 'create_time', title: '添加时间'}
        , {field: 'update_time', title: '更新时间'}
      ]]
      , id: 'testReload'
      , page: false
      , limit: 1000
    });
    var $ = layui.$, active = {
      reload: function () {
        //执行重载
        table.reload('testReload', {
          page: {curr: 1},
        });
      }
    };


    $('.hui-form-search .layui-btn').on('click', function () {
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
    //监听行工具事件
    table.on('toolbar(admin_table)', function (obj) {
      console.log(obj);
      if (obj.event === 'refresh') {
        table.reload('testReload');
      }
    });

  });
</script>
